 <#include "admin/template/page/head_lib.html">
	 <script type="text/javascript" src="https://cdn.bootcss.com/distpicker/2.0.5/distpicker.min.js"></script>
<body>
	<div class="layui-fluid">
	<input type="hidden" name="user_id"/>
	  <div class="layui-form-item">
	    <label class="layui-form-label">用户名称</label>
	    <div class="layui-input-inline" >
	      <input type="text"  name="user_name" required="" lay-verType="tips" lay-verify="required" placeholder="请输入用户名称" autocomplete="off" class="layui-input" readonly="readonly"/>
	    </div>
		<label class="layui-form-label">身份证</label>
		<div class="layui-input-inline">
			<input type="text" name="id_card" required="" lay-verType="tips" lay-verify="identity|number" placeholder="请输入身份证" autocomplete="off" class="layui-input"/>
		</div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">手机号</label>
	    <div class="layui-input-inline">
	      <input type="text" name="phone"  lay-verType="tips" lay-verify="phone" placeholder="请输入手机号" autocomplete="off" class="layui-input"/>
	    </div>
		<label class="layui-form-label">金额</label>
		<div class="layui-input-inline">
		  <input type="text" name="money" lay-verType="tips" lay-verify="number" placeholder="请输入金额" autocomplete="off" class="layui-input" readonly="readonly"/>
		</div>

	  </div>
	  <div class="layui-form-item">
		    <label class="layui-form-label">地址</label>
			<div data-toggle="distpicker"  id="target" >
				<select name = "province" class="layui-input-inline" id="province" style="height: 38px;width: 160px" ></select>
				<select name="city" class="layui-input-inline" id="city" style="height: 38px ;width: 160px" ></select>
				<select name="area" class="layui-input-inline" id="area" style="height: 38px ;width: 160px"></select>
			</div>
		</div>
	  <div class="layui-form-item">
		  <label class="layui-form-label">邮寄地址</label>
		  <div class="layui-input-inline">
			  <input type="text" name="address" id="address" lay-verType="tips"  placeholder="请输入邮寄地址" autocomplete="off" class="layui-input" style="width: 280px"/>
		  </div>
	  </div>
		<div class="layui-form-item">
			<label class="layui-form-label">备注</label>
			<div class="layui-input-inline">
				<input type="text" name="remark" id="remark" lay-verType="tips"  placeholder="请填写备注" autocomplete="off" class="layui-input" style="width: 280px"/>
			</div>
		</div>
	  <hr/>
	  <div class="layui-form-item" style="text-align: center;">
     	 <button class="layui-btn" url="system/user/update.json" id="update"><i class="layui-icon">&#xe642;</i>编辑</button>
     	 <button type="button" class="layui-btn layui-btn-primary" function="close">关闭</button>
    </div>
		<script>
			layui.use(['layer','jquery'],function () {
				var layer = layui.layer,
					$ = layui.$;
				$(function () {
                    $.getUrlParam = function (name) {
                        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                        var r = window.location.search.substr(1).match(reg);
                        if (r != null) return unescape(r[2]); return null;
                    };
                    var user_id = $.getUrlParam('user_id');
                    $.ajax({
                        url: 'system/user/detail',
                        type: 'post',
                        data: 'user_id='+user_id,
                        dataType: 'json',
                        success: function (data) {
                            $("input[name=user_name]").val(data.user_name);
                            $("input[name=user_id]").val(data.user_id);
                            $("input[name=id_card]").val(data.id_card);
                            $("input[name=phone]").val(data.phone);
                            $("input[name=money]").val(data.money);
                            $("input[name=remark]").val(data.remark);
                            var province = data.province;
                            var city = data.city;
                            var area = data.area;
                            var address = data.address;
                            if (province != "" && city != "" && area != ""){
                                $('#target').distpicker('destroy');
                                $('#target').distpicker({
                                    province: province,
                                    city: city,
                                    district: area
                                });
                            }
                            if (address != "" && address != ""){
                                $("#address").val(address)
                            }
                        }
                        ,error: function (data) {
                            layer.msg("对不起发生未知异常!请刷新页面重试！")
                        }
                    })

					$("#update").click(function () {
                        var identity = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                        var tel  = /^1\d{10}$/;
                        var user_name = $("input[name=user_name]").val();
                        var user_id = $("input[name=user_id]").val();
                        var id_card = $("input[name=id_card]").val();
                        var phone = $("input[name=phone]").val();
                        var money =  $("input[name=money]").val();
                        var remark =  $("input[name=remark]").val();
                        var province =  $("#province").val();
                        var city =  $("#city").val();
                        var area =  $("#area").val();
                        var address =  $("#address").val();
                        var province_data =  provinceCode();
                        var city_data =  cityCode();
                        var area_data =  areaCode();
                        var flag = true;
                        if(!tel.test(phone)) {
                            flag = false;
                            layer.msg("请输入正确的手机号!");
                        }  else if(!identity.test(id_card)) {
                            flag = false;
                            layer.msg("请输入正确的身份证!");
                        }

                        if (flag){
                            $.ajax({
                                url: 'system/user/update.json',
                                type: 'post',
                                data: {id_card:id_card,phone:phone,address:address, province:province,remark:remark
                                    ,city:city,area:area,province_data:province_data,city_data:city_data,area_data:area_data,user_id:user_id},
                                dataType: 'json',
                                success: function (data) {
                                    if (data.code == 200){
                                        layer.msg("修改成功",{time:0.5*1000},function () {
                                            var index = parent.layer.getFrameIndex(window.name);
                                            parent.layer.close(index);  //关闭当前页
                                        })
                                    }else {
                                        layer.msg("对不起，修改失败！")
                                    }
                                }
                                ,error: function (data) {
                                    layer.msg("对不起，服务器发生未知异常!请刷新页面重试！")
                                }
                            })
						}



                    })
                    function provinceCode(){
                        var firstCode= $('#province').find('option:selected').attr('data-code');  //获取被选中的option的属性值
                        return firstCode;	//返回最终获取的code码
                    };

                    function cityCode(){
                        var secondCode = $('#city').find('option:selected').attr('data-code');  //获取被选中的option的属性值
                        return secondCode;	//返回最终获取的code码
                    };

                    function areaCode(){
                        var thirdCode= $('#area').find('option:selected').attr('data-code');
                        return thirdCode;	//返回最终获取的code码
                    };

                })




            })


		</script>



	</div>
</body>

</html>
